//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using System.Xml;
using CommunityServer.Components;

namespace CommunityServer.Components
{
	public class PollCensorshipModule : ICSModule
	{
		public void Init(CSApplication csa, XmlNode node)
		{
			csa.PrePostUpdate +=new CSPostEventHandler(csa_BeforeProcessPost);
		}

		private void csa_BeforeProcessPost(IContent content, CSPostEventArgs e)
		{
			if(e.State == ObjectState.Create || e.State == ObjectState.Update)
			{
				Post p = content as Post;
				if(p != null && p.HasPoll)
				{
					p.PollDescription = Transforms.CensorPost(p.PollDescription);
					p.PollTitle = Transforms.CensorPost(p.PollTitle);
					
					foreach (PollItem item in p.GetPollItems())
					{
						item.Answer = Transforms.CensorPost(item.Answer);
						p.UpdatePollItem(item);
					}
				}
			}
		}
	}
}
